JSP If else condition using JSTL if and choose tags

您所在的位置:网站首页 jstl if else JSP If else condition using JSTL if and choose tags

JSP If else condition using JSTL if and choose tags

#JSP If else condition using JSTL if and choose tags| 来源: 网络整理| 查看: 265

We can use JSTL tags in JSP pages to evaluate if…else scenarios. – c:if – c:choose  

JSTL Core “if” Tag

  The “if” tag evaluates an expression and displays its body content only if the expression evaluates to true.  

Attributes of if tag:

The if tag has following attributes:

Required attribute test – This represents the condition to evaluate and is mandatory attribute.

Optional attribute var – This is the aame of the variable to store the condition’s result. scope – Scope of the variable to store the condition’s result.  

Example:

Tag Example   

Quanity available is:

 Output

  This would produce following result:

Quanity available is: 100  

Disadvantage:

  There is no else in JSTL. So for if..else scenarios, you have to do multiple if tags or you can use JSTL choose tag.

 

JSTL Core “choose” Tag

  The “choose” tag works like a Java switch statement in that it lets you choose between a number of alternatives. While the switch statement has case statements, the choose tag has when tags. A a switch statement has default clause to specify a default action and similar way choose has otherwise as default clause.  

Attribute:

The choose tag does not have any attribute.

The when tag has one attribute “test” which represents the condition to evaluate.

The otherwise tag does not have any attribute.

 

Example

 

Tag Example        

${quantity} Available

          

Not available

    Output

  This would produce following result:

Not available  

© 2016 – 2018, https:. All rights reserved. On republishing this post, you must provide link to original post

Share this article :Click to share on LinkedIn (Opens in new window)Click to share on Facebook (Opens in new window)Click to share on Twitter (Opens in new window)MoreClick to share on Pinterest (Opens in new window)Click to share on Flipboard (Opens in new window)Click to share on Tumblr (Opens in new window)Click to share on Reddit (Opens in new window)Click to share on Pocket (Opens in new window)RelatedPopular Articles you may like : Java 8 Interview Questions   RESTful CRUD operations using Jersey and Hibernate   Frequently asked Java Programming Interview questions on Strings


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3